<?php
require_once("conf/db_connection.php");

$size = $_GET['size'];
$fleet = $_GET['fleet'];
$own = $_GET['own'];
$get_size = $_GET['size_filter'];
if($get_size=="")
{
$get_size = "20";
}
//$query_truck="SELECT * FROM truck WHERE is_available='1' AND is_deleted='0' AND size_filter='".$get_size."' AND (equipment_size LIKE '%".$size."%' AND fleet_group LIKE '%".$fleet."%' AND ownership LIKE '%".$own."%') ORDER BY available_date_time ASC";
$query_truck="SELECT * FROM truck WHERE (is_available='1' OR is_available='2') AND is_deleted='0' AND size_filter='".$get_size."' AND (equipment_size LIKE '%".$size."%' AND fleet_group LIKE '%".$fleet."%' AND ownership LIKE '%".$own."%') ORDER BY ownership_num ASC, available_date_time ASC";
$result_truck=mysql_query($query_truck) or die("SELECT TRUCKS ".mysql_error());

$size = $size==""?"All":$size;
$fleet = $fleet==""?"All":$fleet;
$own = $own==""?"All":$own;

$size = "<span style='font-style:italic'>".$size."</span>";
$fleet = "<span style='font-style:italic'>".$fleet."</span>";
$own = "<span style='font-style:italic'>".$own."</span>";

$search_string = "<span style='color:white'><span style='font-weight:bold;'>Equipment Size:</span> ".$size."&nbsp;&nbsp;&nbsp; <span style='font-weight:bold;'>Fleet Group:</span> ".$fleet."&nbsp;&nbsp;&nbsp; <span style='font-weight:bold;'>Ownership:</span> ".$own."</span>&nbsp;&nbsp;&nbsp;";

$opt_size = "";

if($get_size=="20")
{
//$opt_size .= "<option value='10'>10</option>";
$opt_size .= "<option value='20' selected='true'>20</option>";
$opt_size .= "<option value='40'>40</option>";
}
if($get_size=="40")
{
//$opt_size .= "<option value='10'>10</option>";
$opt_size .= "<option value='20'>20</option>";
$opt_size .= "<option value='40' selected='true'>40</option>";
}

?>
<html>
<head>
<script type="text/javascript" src="lib/js/main.js"></script>
<script type='text/javascript'>
function popSearch()
{
	xmlhttp_assign=GetXmlHttpObject();
	if (xmlhttp_assign==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	var url="ajax_asearch_queue.php";
	xmlhttp_assign.onreadystatechange=function (){
	  if (xmlhttp_assign.readyState==4)
	  {
		parent.disableDiv();
		parent.document.getElementById("pop_div_search").innerHTML = xmlhttp_assign.responseText;
		parent.showPopSearchDiv();
	  }
	}
	xmlhttp_assign.open("GET",url,true);
	xmlhttp_assign.send(null);	
}
</script>
<style type = "text/css">
#hor-minimalist-b {
	background-color: #FFFFFF;
    border-collapse: collapse;
    font-family: Georgia;
    font-size: 12px;
    margin: 10px;
    text-align: center;
    width: 900px;
}
#hor-minimalist-b th {
    border-bottom: 2px solid #5F0C0C ;
    color: #5F0C0C;
    font-size: 12px;
    font-weight: bold;
    padding: 10px 8px;
}
#hor-minimalist-b td {
    border-bottom: 1px solid #888888;
    color: #000000;
    padding: 6px 8px;
}
#hor-minimalist-b tbody tr:hover td {
    //color: #0000CC;
	background-color:#BCC5C6;
}
</style>
</head>
<body>
<table border='1' width='900' style='background-color:white;margin-left:auto;margin-right:auto;background-color:#5F0C0C;color:white;font-family:Georgia;font-size:12px'>
<th>TRUCK QUEUE</th>
</table>
<table width='900' style='background-color:black;margin-left:auto;margin-right:auto;color:white;font-family:Georgia;font-size:12px'>
<!--<tr>
	<td align = 'right'><?php echo $search_string; ?><input onClick='popSearch()' type = 'button' id = 'btn_asearch' name = 'btn_asearch' value = 'Advance Search' /></td>
</tr>-->
<tr>
	<td align = 'left' style='font-weight:bold;'>Size:
	<select id='sel_size' name='sel_size' onChange=document.location.href='truck_queue_list.php?size_filter='+this.value >
		<?php echo $opt_size ?>
	</select></td>
</tr>
</table>
<table id='hor-minimalist-b' border='0' width='900' style='margin-left:auto;margin-right:auto'>
<thead>
<tr>
	<th>&nbsp;</th>
	<th>Plate Number</th>
	<th>Equipment Size</th>
	<th>Equipment Type</th>
	<th>Contact Person</th>
	<th>Contact Number</th>
	<th>Remarks</th>
</tr>
</thead>
<?php
while($row_truck = mysql_fetch_array($result_truck))
{
if($row_truck['is_available']=="1")
{
	$img_avail = "<img src='image/green_btn.png' style='cursor:pointer' title='This vehicle is available.'>";
	//onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."')
}
else if($row_truck['is_available']=="0")
{
	$img_avail = "<img src='image/red_btn.png' style='cursor:pointer' title='This vehicle is unavailble.'>";
	//onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."')
}
else if($row_truck['is_available']=="2")
{
	$img_avail = "<img src='image/orange_btn.png' style='cursor:pointer' title='This vehicle is unavailble.'>";
	//onClick=checkAvailable('".$row_truck['id']."','".$row_truck['is_available']."')
}
?>
<tbody>
<tr>
	<td style="text-align:left; font-family:Georgia; font-size:12px"><?php echo $img_avail ?></td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["plate"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["equipment_size"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["equipment_type"] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck['contact_person'] ?>&nbsp;</td>
	<td style="text-align:center; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck['contact_cellphone'] ?>&nbsp;</td>
	<td style="text-align:left; font-family:Georgia; font-size:12px">&nbsp;<?php echo $row_truck["remarks"] ?>&nbsp;</td>
</tr>
</tbody>
<?php
}
?>
</table>		
</body>
</html>